FROM node:16-alpine3.16
LABEL maintainer="shanke"
ARG APP_URL=https://gitee.com/523757325/torrent-manager-node.git
ARG APP_BRANCH=master
ARG WEB_URL=https://gitee.com/523757325/torrent-manager-web.git
ARG WEB_BRANCH=master
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
    LANG=zh_CN.UTF-8 \
    SHELL=/bin/bash \
    PS1="\u@\h:\w \$ " \
    WEB_DIR=/web \
    APP_DIR=/app

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
    && apk update -f \
    && apk upgrade \
    && apk --no-cache add -f bash \
                             coreutils \
                             moreutils \
                             git \
                             curl \
                             wget \
                             tzdata \
                             perl \
                             openssl \
                             openssh \
    && rm -rf /var/cache/apk/* \
    && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone \
    && touch ~/.bashrc \
    && git config --global user.email "torrentmanager@@users.noreply.gitee.com" \
    && git config --global user.name "torrentmanager" \
    && git config --global pull.rebase true \
    && npm install -g pm2 --registry=https://registry.npm.taobao.org

WORKDIR ${WEB_DIR}
RUN git clone -b ${WEB_BRANCH} ${WEB_URL} ${WEB_DIR} \
    && cd ${WEB_DIR} \
    && npm install --registry=https://registry.npm.taobao.org \
    && npm run build

WORKDIR ${APP_DIR}
RUN git clone -b ${APP_BRANCH} ${APP_URL} ${APP_DIR} \
    && cd ${APP_DIR} \
    && chmod 777 ${APP_DIR}/docker-entrypoint.sh \
    && chmod 777 ${APP_DIR}/shell/*.sh \
    && npm install --registry=https://registry.npm.taobao.org


# 
VOLUME ["/config", "/manage"]
EXPOSE 6699

ENTRYPOINT ["./docker-entrypoint.sh"]

# docker build -t shanke520/torrentmanager:latest .
# docker tag shanke520/torrentmanager:0.04 shanke520/torrentmanager:latest
# docker save tm:test -o tm.tar
# scp .\tm.tar root@192.168.123.111:/mnt/user/mydata/comm
# docker load -i tm.tar
# /usr/local/emhttp/plugins/dynamix.docker.manager/scripts/docker run -d --name='tm' --net='host' -e TZ="Asia/Shanghai" -e HOST_OS="Unraid" -v '/mnt/user/mydata':'/manage':'rw' -v '/mnt/user/appdata/tm':'/config':'rw' 'tm:test'
